#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main()
{
  int fd = open("log.txt",O_RDONLY);
  dup2(fd,0);//将从stdin中读取改为从fd的地址文件中读取

  char buffer[2048];
  size_t s = read(0,buffer,sizeof(buffer));
  if(s > 0)
  {
    buffer[s] = 0;
    printf("stdin redir:\n%s\n",buffer);
  }

  return 0;
}
